<!--Code for updating an announcement to the database-->
1<?php

if (isset($_POST['submitEdit'])) {

    $title = $_POST['annTitle'];
    $desc = $_POST['annDesc'];
    $date = $_POST['annDate'];
    $id = $_POST['id'];

    include 'DBLibrary/config.php';
    include 'DBLibrary/openDB.php';

    mysql_select_db("rotaract");


    $query = "SELECT * FROM announcement WHERE id='$id'";
    $result = mysql_query($query) or die(mysql_error());
    $row = mysql_fetch_array($result);

    define('FileFolder', 'announcementImages/');

    if (isset($_POST['submitEdit'])) {
        $dafile = $_FILES['imageUpload']['name'];
        $target = FileFolder . $dafile;
        if (strcmp($target, $row['imageurl']) != 0) {
            move_uploaded_file($_FILES['imageUpload']['tmp_name'], $target);
        }
    }
    if (strcmp($target, "announcementImages/") == 0) {
        $result = mysql_query("UPDATE `rotaract`.`announcement` SET `title`= '$title', `date`= '$date', `desc`= '$desc' WHERE `announcement`.`id`= $id") or die(mysql_error());
    }
    else
        $result = mysql_query("UPDATE `rotaract`.`announcement` SET `title`= '$title', `date`= '$date', `desc`= '$desc', `imageurl`= '$target' WHERE `announcement`.`id`= $id") or die(mysql_error());

    $confirm = 'Update successful!';
}
?>
